#include<iostream>
#include<optional>
#include<vector>

std::optional<int> FindByElement(std::vector<int>v,int index)
{   
    if(index<0||index>=v.size())
    {
            return std::nullopt;//空对象
    }
    return v[index];

}
int main()
{
    std::vector<int> v={1,2,3,4,5};
    auto value=FindByElement(v,2);
    if(value)
    {
        std::cout<<*value<<std::endl;
    }
    {
        std::cout<<"没找到!\n"<<std::endl;
    }
    return 0;
}